package com.hmall.mapper;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hmall.domain.po.Datas;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.hmall.domain.po.Datas2;
import com.hmall.domain.po.Information;
import com.hmall.domain.vo.DataVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author HBQ
 * @since 2025-10-22
 */
public interface DataMapper extends BaseMapper<Datas> {


    @Select("SELECT i.name,d.xingzuo,d.mbti,d.hobby,i.introduce,i.image\n" +
            "FROM information i\n" +
            "JOIN `data` d on i.user_id=d.user_id\n" +
            "WHERE d.mbti = #{item} ")
    DataVO getQuery(String item);

    @Update("update data set xingzuo = #{datas.xingzuo}, mbti = #{datas.mbti}, hobby = #{datas.hobby}, life_philosophy = #{datas.lifePhilosophy}, social_preference = #{datas.socialPreference} where user_id = #{id}")
    void updateData(@Param("datas") Datas datas, @Param("id") Long id);


    @Insert("insert into data (xingzuo, mbti, hobby, life_philosophy, social_preference, user_id) values (#{datas.xingzuo}, #{datas.mbti}, #{datas.hobby}, #{datas.lifePhilosophy}, #{datas.socialPreference}, #{userId})")
    void saveData(@Param("datas") Datas datas,@Param("id") Long  id);

    Page<Datas2> pageQuery(IPage<Datas2> page);


    @Update("UPDATE data " +
            "SET xingzuo=#{datas.xingzuo}, " +
            "mbti=#{datas.mbti}, " +  // 补充完整赋值表达式
            "hobby=#{datas.hobby}, " +
            "life_philosophy=#{datas.lifePhilosophy}, " +
            "social_preference=#{datas.socialPreference} " +  // 移除末尾多余逗号
            "WHERE user_id=#{userId}")  // 与参数名保持一致
    void saveUser(@Param("datas") Datas datas, @Param("userId") Long userId);

//    @Select("SELECT i.id,i.name,d.xingzuo,d.mbti,d.hobby,i.introduce,i.image\n" +
//            "FROM information i\n" +
//            "JOIN `data` d on i.user_id=d.user_id\n" +
//            "where d.mbti=#{mbti}")
//    Page<Datas> pageQuery();
}
